package com.by.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by.entity.Order;
import com.by.service.OrderService;
import com.by.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄佳辉
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/v1/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/save")
    public Result<String> save(@RequestBody Order order){
        boolean saveFlag = orderService.saveWithDetail(order);
        return saveFlag ? Result.success("下单成功"):Result.fail("下单失败");
    }

    @GetMapping("/query")
    public Result<Page<Order>> query(Integer page, Integer pageSize){
        Page<Order> pageOrder = new Page<>(page, pageSize);
        orderService.page(pageOrder);
        return Result.success("订单列表",pageOrder);
    }


    @GetMapping("/get")
    public Result<Order> get(String id){
        Order order = orderService.getWithDetail(id);
        return Result.success("订单详情",order);
    }

}
